package cn.billi.cloud.basic.consume;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate;
import cn.billi.cloud.basic.consume.service.UserService;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@EnableDiscoveryClient
public class App {
  public static void main(String[] args) {
    System.out.println("Billi basic service consume!");
    ApplicationContext context = SpringApplication.run(App.class, args);
    UserService service = context.getBean(UserService.class);
    StopWatch stopwatch = new StopWatch("queryNames");
    stopwatch.start();
    for (int i = 0; i < 10; ++i) {
      System.out.println(service.queryNames());
      // try {
      // Thread.sleep(500L);
      // } catch (InterruptedException e) {
      // e.printStackTrace();
      // }
    }
    stopwatch.stop();
    System.out.println(stopwatch.prettyPrint());
  }

  @Bean
  @LoadBalanced
  public RestTemplate restTemplate() {
    return new RestTemplate();
  }
}
